package com.hspedu.method;

/**
 * @author DL5O
 * @version 1.0
 */
public class ThreadMethod02 {
    public static void main(String[] args) throws InterruptedException {
        int count = 0;
        Test test = new Test();
        test.start();
        while (true){
            System.out.println("hello " + (++count));
            Thread.sleep(1000);
            if(count == 5){
                System.out.println("让test 线程先执行");
//                test.join();//线程插队一定会成功
                Thread.yield();//线程礼让

                //让test 线程先执行，执行后可以看到，当执行join后，主线程就不再执行，
                // 当这个test线程执行完毕后，主线程才继续执行
            }
            if(count == 20){
                break;
            }
        }


    }
}

class Test extends Thread{
    private int count = 0;
    @Override
    public void run() {
        while(true){
            System.out.println("hi " + (++count));
            try {
                Thread.sleep( 1000);//休眠1秒
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (count == 20){
                break;
            }
        }

    }
}
